package com.cos.lession51.factory;

import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author: COS
 * @time: 2022/3/4 11:25
 * @description:
 */
public class MyFactory implements FactoryBean {
    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/3/4 11:28
     * @description: 返回实际对象的方法,在这个方法里面创建好复杂的对象在返回出去
     */
    @Override
    public Object getObject() throws Exception {
        //1 加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2 获取链接
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/qf2111", "cos", "123456");
        //3 返回对象
        return con;
    }

    @Override
    public Class<?> getObjectType() {
        //返回的对象是属于什么类型的数据
        //返回java.sql.Connection
        return Connection.class;
    }

    @Override
    public boolean isSingleton() {
        //true为设置单例模式
        //false为设置多例模式
        return false;
    }
}
